#coding=utf-8

require "aio/core"

class Aio::Module::Cmd::Cisco::ShowInv < Aio::Module::Cmd::Cisco
	include Aio::Module

	def initialize
		super({
			:cmd_full 		=> "show inventory",
			:cmd_short 		=> "sh inv",
			:author				=> "Elin",
			:description  => "This is Cisco Command# show inventory",
			:platform			=> "all",
		})
	end

	def parse
		context = self.context.dup
		inv_info = {}
		useful[:inventory] = inv_info

		context.readline_range_loop(/NAME:/, reg_blank) do |cont|
			slot_info = {}
			name = ""
			description = ""

			cont.readline_match_block(/NAME: "(?<name>.*)", DESCR: "(?<description>.*)"/) do |block|
				name = block[:name]
				description = block[:description]
			end
			cont.readline_match_block(/PID: (?<pid>[^\s]+).*SN: (?<sn>[^\s]+)/) do |block|
				sn = block[:sn]
				inv_info[sn.to_sym] = slot_info
				block.update(slot_info, :name, name)
				block.update(slot_info, :description, description)
				block.update(slot_info, :pid)
				block.update(slot_info, :sn)
			end
		end
	end
end

